package finalgame.Engine;
import java.util.Map;

import finalgame.Engine.pokemon.*;
import finalgame.Engine.trainer.Trainer;

public class GeneratePokemon {
	public static String[] pokemonlist;
	public static Map<String, Integer> genMap;
	//gen 1: 0-6
	//gen 2: 7-11
	//gen 3: 12-17
	//gen 4: 18-23
		
	public static Pokemon generatePokemon(Trainer t){
		Pokemon wildPokemon;
		String pokemonName;
		int level;
		do {
			pokemonName = pokemonlist[generateRandomNumber(pokemonlist.length)];
			level = genMap.get(pokemonName).intValue();
		} while(level > findAverageLevel(t));
		
		System.out.println(pokemonName);
		return Pokemon.getNewPokemon(pokemonName, generateLevel(t));
	}
	
	private static int generateLevel(Trainer t){
		int averagelevel = findAverageLevel(t);
		int generatedLevel;
		
		generatedLevel = (int) Math.round(Math.random() * averagelevel);
		return generatedLevel;
	}
	
	private static int generateRandomNumber(int num){
		return (int) (Math.random() * num);
	}
	
	private static int findAverageLevel(Trainer t){
		finalgame.Engine.pokemon.Pokemon[] plist = t.getPokemonInventory();
		int numofPokemon = t.getNumberOfPokemon();
		int average = 0;
		for(int i =0; i<numofPokemon; i++){
			average = average + plist[i].getLevel();
		}
		if(numofPokemon > 0)
			average = average / numofPokemon;
		return average;
		
	}
}
